#include <stdio.h>//printf
#include <fcntl.h> //O_RDWR
#include <stdlib.h>//atoi
#include <unistd.h>//close write

/*
 * @description		: main主程序
 * @param - argc	: argv数组元素个数
 * @param - argv	: 具体参数
 * @return			: 0 成功;其他 失败
 */

int main(int argc,char *argv[])
{
    int fd,ret;
    unsigned char buf[1];

    if(argc!=3)
    {
        printf("Usage:\n"
		"\t./ledApp /dev/led 1		@ close LED\n"
		"\t./ledApp /dev/led 0		@ open LED\n"
		);
		return -1;
    }
    /*打开设备*/
    fd = open(argv[1],O_RDWR);
    if(fd<0)
    {
        printf("file %s open failed!\r\n", argv[1]);
		return -1;
    }
    /*字符转int*/
    buf[0]=atoi(argv[2]);
    /*向驱动写入数据*/
    ret = write(fd,buf,sizeof(buf));
    if(ret<0)
    {
        printf("LED Control Failed!\r\n");
		close(fd);
		return -1;
    }
    /*关闭设备*/
    close(fd);
    return 0;
}